package com.zmn.brs.services.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.zmn.brs.common.constant.BrsMqConst;
import com.zmn.brs.common.model.mq.StaffOperateRecordMq;
import com.zmn.brs.services.interfaces.IStaffOperateRecordService;
import com.zmn.manager.mq.interfaces.ZmnMQSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * 类描述：员工操作记录接口实现
 *
 * @author xujie
 * @since 2021/03/15 11:01
 */
@Slf4j
public class IStaffOperateRecordServiceImpl implements IStaffOperateRecordService {

    @NacosValue(value = "${spring.mq.topic.brs}", autoRefreshed = true)
    String brsTopic;

    private static final String STAFF_ID = "0";

    @Resource
    private ZmnMQSender zmnMqSender;

    @Override
    public void record(StaffOperateRecordMq recordMq) {

        if (StringUtils.isEmpty(recordMq.getStaffId()) || STAFF_ID.equals(recordMq.getStaffId())) {
            log.error("【安全监控】员工操作记录，发送MQ消息失败，员工Id为空或者为0，消息内容：{}", recordMq);
            return;
        }
        zmnMqSender.send(brsTopic, BrsMqConst.STAFF_OPERATE_RECORD_MESSAGE, UUID.randomUUID().toString(), JSON.toJSONString(recordMq));
        log.info("【安全监控】员工操作记录，发送MQ消息内容：{}", recordMq);
    }

}
